package com.goods.controller.business;

import com.goods.business.service.InStockService;
import com.goods.common.model.business.InStock;
import com.goods.common.response.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.session.RedisSessionProperties;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/business/inStock")
public class InStockController {
    @Autowired
    private InStockService inStockService;

    @PostMapping("/addIntoStock")
    public ResponseBean addIntoStock(@RequestParam  Map  map){
        boolean integer = inStockService.addIntoStock(map);
        if(integer){
            return ResponseBean.success();
        }else{
            return ResponseBean.error("error");
        }

    }
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id) {
        boolean isFlag = inStockService.remove(id);
        if (isFlag) {
            return ResponseBean.success();
        } else {
            return ResponseBean.error("error");
        }
    }

    @GetMapping("/detail/{id}")
    public ResponseBean detail(@PathVariable Long id, Integer pageNum) {
        Map map = inStockService.detail(id, pageNum);
        return ResponseBean.success(map);

    }

    @GetMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id) {
        boolean isFlag = inStockService.delete(id);
        if (isFlag) {
            return ResponseBean.success();
        } else {
            return ResponseBean.error("error");
        }
    }

    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id) {
        boolean isFlag = inStockService.back(id);
        if (isFlag) {
            return ResponseBean.success();
        } else {
            return ResponseBean.error("error");
        }
    }

    @GetMapping("/findInStockList")
    public ResponseBean findInStockList(@RequestParam Map map) {
        Map map1 = inStockService.findInStockList(map);
        return ResponseBean.success(map1);
    }
}
